package offer.nowcoder.array;

/**
 * @author DengYuan2
 * @create 2021-02-09 21:38
 */
public class n_4 {
    public static void main(String[] args) {
        int[][] arr={
                {1,2,8,9},
                {2,4,9,12},
                {4,7,10,13},
                {6,8,11,15}
        };
        int target=6;
        boolean res = Find(target, arr);
        System.out.println(res);
    }

    public static boolean Find(int target, int [][] array) {
        int row=array.length;
        int col=array[0].length;
        int i=0,j=col-1;
        while (i<row&&j>=0){
            if (array[i][j]==target){
                return true;
            }else if (array[i][j]<target){
                i++;
            }else {
                j--;
            }
        }
        return false;
    }
}
